//映射（例子）
type Item = { a: string, b: number, c: boolean }
type T1 = { [P in 'x' | 'y']: number } // { x: number, y: number }
type T2 = { [P in 'x' | 'y']: P } // { x: "x", y: "y" }
type T3 = { [P in 'a' | 'b']: Item[P] } // { a: string, b: number }
type T4 = { [P in keyof Item]: Item[P] } // { a: string, b: number, c: boolean }

type User = {
    name: string,
    password: string,
    address: string,
    phone: string,
}

//映射（可以添加 readonly 或 ? 修改原有对象的属性的设置）
type MyPartial<T> = {
    readonly [P in keyof T]?: T[P]
}

type UserPartial = MyPartial<User>

//TypeScript 4.1 版本允许我们使用 as 子句对映射类型中的键进行重新映射。它的语法如下
type Getters<T> = {
    [K in keyof T as `get${Capitalize<string & K>}`]: () => T[K]
}

interface Person {
    name:string,
    age:number,
    location:string
}

type LazyPerson = Getters<Person> 
// {
//   getName: () => string; 
//   getAge: () => number;
//   getLocation: () => string;
// }
